#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 3;
int TT = 1, T, a[N], n, b[N], ans;
void dfs(int x)
{
    if (clock() >= CLOCKS_PER_SEC * 0.7)
        return;
    if (x == n + 1)
    {
        int X = 0, Y = 0, c = 0;
        for (int i = 1; i <= n; i++)
        {
            if (b[i] == 1)
            {
                if (a[X] == a[i]) c += a[i];
                X = i;
            }
            else
            {
                if (a[Y] == a[i]) c += a[i];
                Y = i;
            }
        }
        ans = max(ans, c);
        return;
    }
    b[x] = 1;
    dfs(x + 1);
    b[x] = 2;
    dfs(x + 1);
}
void init()
{
    map<int, int> p;
    cin >> n;
    ans = 0;
    int c = 0, s = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++)
    {
        if (p[a[i]])
        {
            if (p[a[i]] == 1) c++;
            s += a[i];
        }
        p[a[i]]++;
    }
    if (c < 3)
    {
        cout << s << "\n";
        return;
    }
    dfs(1);
    cout << ans << "\n";
}
signed main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    for (; TT <= T; TT++) init();
    return 0;
}
